package link.idns.g01.jdbcbridge.utils;

import lombok.Data;

@Data
public class Response<T> {

    String message;

    int code;

    T data;

    public static <T> Response<T> success(T data, String msg) {
        Response<T> dto = new Response<T>();
        dto.setData(data);
        dto.setCode(0);
        dto.setMessage(msg);
        return dto;

    }

    public static Response<Object> successWithMsg(String msg) {
        Response<Object> dto = new Response<Object>();
        dto.setData(null);
        dto.setCode(0);
        dto.setMessage(msg);
        return dto;
    }

    public static <T> Response<T> successWithData(T data) {
        Response<T> dto = new Response<T>();
        dto.setData(data);
        dto.setCode(0);
        return dto;
    }

    public static Response<Object> fail(String msg) {
        Response<Object> dto = new Response<Object>();
        dto.setCode(1);
        dto.setMessage(msg);
        return dto;
    }

    public static <T> Response<T> failWithData(String msg, T data) {
        Response<T> dto = new Response<T>();
        dto.setCode(1);
        dto.setMessage(msg);
        dto.setData(data);
        return dto;
    }
}
